gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\svm\svmclass.m
function [Ipred,fpred] = svmclass(Xtst,Xtrn,Itrn,alpha,bias,ker,arg,info) % SVMCLASS classifies patterns using SVM decision rule. % [Ipred,fpred] = svmclass(Xtst,Xtrn,Itrn,Alpha,bias,ker,arg) % % Input: % Xtst [DxN] test points. % Xtrn [DxM] training points. % Itrn [1xM] labels of trainign points. % Alpha [1xM] Lagrange multipliers. % bias [1x1] bias. % ker [string] kernel identifier (see help kernel). % arg [] arguments of given kernel (see help kernel). % % Output: % Ipred [1xN] labels of test points (1,2). % fpred [1xN] value of output function for each point (If greater or % equal to 0 then class is 1 else class is 2). % % See also SVMCLASSM, SVM. % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) 23.12.1999, 5.4.2000 % Modifications % 19-September-2001, V. Franc, comments changed. if nargin < 8, info =0; end if nargin < 7, arg=[]; end %inx=find(alpha ~=0); %Itrn=Itrn(inx); %Xtrn=Xtrn(:,inx); Ytrn=itosgn(Itrn); Ipred=zeros(1,size(Xtst,2)); fpred=zeros(1,size(Xtst,2)); for i = 1:size(Xtst,2), xtst = Xtst(:,i); K=kernel(xtst,Xtrn,ker,arg).*Ytrn; fpred(i) = (K*alpha' + bias)'; if fpred(i) >= 0, Ipred(i) = 1; else Ipred(i) = 2; end if info & mod(i*100/size(Xtst,2),5) == 0, disp(sprintf('Predicted %.2f %%',i*100/size(Xtst,2) )); end end return;